<template>
  <div>
    <el-row :gutter="10">
      <el-col :span="12">
        <el-card style="margin-left: 25px;margin-top: 20px">
          <div style="width: 700px;height: 400px" id="line">

          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card style="margin-top: 20px">
          <div style="width: 700px;height: 400px" id="bar">

          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="10">
      <el-col :span="12">
        <el-card style="margin-left: 25px;margin-top: 20px">
          <div style="width: 700px;height: 400px" id="pie">

          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
      </el-col>
    </el-row>
  </div>
</template>
<script>
import request from "@/utils/request";
import * as echarts from 'echarts'
const option = {
  title:{
    text:"献血人数折线图",
    left:'center'
  },
  legend: {
    // Try 'horizontal'
    orient: 'vertical',
    left:'left'
  },
  tooltip:{
    trigger: 'axis'
  },
  xAxis: {
    type: 'category',
    data: []
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      name:'人数',
      data: [],
      type: 'line',
      smooth: true
    }
  ]
};

const baroption = {
  title:{
    left:'center',
    text:"库存血型分布柱状图"
  },
  tooltip:{
    trigger: 'axis'
  },
  xAxis: {
    type: 'category',
    data: []
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      name:'血型库存',
      data: [],
      type: 'bar',
      smooth: true
    }
  ]
};

const pieoption = {
  title:{
    text:"库存血型统计",
    subtext:"比例图",
    left:'center'
  },
  tooltip: {
    trigger: 'item'
  },
  legend: {
    top:'15%',
    orient: 'vertical',
    left: '15%'
  },
  series: [
    {
      label:{
        show:true,
        formatter(param){
          return param.name + '(' + param.percent +'%)'
        }
      },
      radius: '60%',
      center:['50%','50%'],
      name:'血型',
      data: [],
      type: 'pie',
      smooth: true
    }
  ]
};
export default {
  data() {
    return {

    };
  },
  mounted() {
    let lineDom = document.getElementById('line');
    let lineChart=echarts.init(lineDom);

    let barDom = document.getElementById('bar');
    let barChart=echarts.init(barDom);

    let pieDom = document.getElementById('pie');
    let pieChart=echarts.init(pieDom);


    request.get('bloodbanks/charts').then(res=>{
      if(res.code === '200'){
        option.xAxis.data=res.data.line?.map(v => v.date) || []
        option.series[0].data=res.data.line?.map(v => v.value) || []
        lineChart.setOption(option)
        baroption.xAxis.data=res.data.bar?.map(v => v.name) || []
        baroption.series[0].data=res.data.bar?.map(v => v.value) || []
        barChart.setOption(baroption)
        pieoption.series[0].data=res.data.bar || []
        pieChart.setOption(pieoption)
      }
    })
  },
  methods: {
  },
};
</script>
<style>

</style>